# Maintainer: George Rawlinson <grawlinson@archlinux.org>
# Contributor: Alexander 'z33ky' Hirsch <1zeeky@gmail.com>

pkgname=libabigail
pkgver=2.2
pkgrel=1
pkgdesc='ABI Generic Analysis and Instrumentation Library'
arch=('loong64' 'x86_64')
license=('Apache')
url='https://sourceware.org/libabigail/'
depends=(
  'libxml2'
  'elfutils'
  'python'
)
makedepends=(
  'git'
  'python-sphinx'
)
options=('debug')
_commit='1f51b9e85dc42dc71caf7fe79436d64c6a3d03f3'
source=("git+https://sourceware.org/git/libabigail.git#commit=$_commit")
b2sums=('SKIP')

pkgver() {
  cd "$pkgname"

  git describe --tags | sed 's/^libabigail-//'
}

prepare() {
  cd "$pkgname"

  autoreconf -fi
}

build() {
  cd "$pkgname"

  ./configure \
    --prefix=/usr \
    --enable-bash-completion \
    --disable-manual \
    --disable-apidoc \
    --disable-static

  make

  # man pages
  make -C doc/manuals man
}

check() {
  cd "$pkgname"

  make check
}

package() {
  cd "$pkgname"

  make DESTDIR="$pkgdir" install

  # man pages
  OLDIFS="$IFS"
  IFS="."
  pushd doc/manuals/man

  # delete Fedora-specific man page
  rm -vf fedabipkgdiff.1

  for filename in *; do
    read -ra PART <<< "$filename"
    section="${PART[1]}"
    install -vDm644 -t "$pkgdir/usr/share/man/man${section}" "$filename"
  done
  IFS="$OLDIFS"
  unset OLDIFS
  popd

  # bash completion
  cd bash-completion
  for filename in abicompat abidiff abidw abilint abipkgdiff; do
    install -vDm644 -t "$pkgdir/usr/share/bash-completion/completions" "$filename"
  done
}
